package com.sky.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.sky.model.dto.ShopPageQueryDTO;
import com.sky.model.dto.UserBehaviorDTO;
import com.sky.Result.PageResult;
import com.sky.service.UserBehaviorService;

@RestController
@RequestMapping("/user-behavior")
public class UserBehaviorController {

    private final UserBehaviorService userBehaviorService;

    @Autowired
    public UserBehaviorController(UserBehaviorService userBehaviorService) {
        this.userBehaviorService = userBehaviorService;
    }

    /**
     * 处理添加浏览量的请求
     *
     * @param userBehaviorDTO 包含用户行为数据的DTO
     */
    @PostMapping("/add-views")
    public void addViews(@RequestBody UserBehaviorDTO userBehaviorDTO) {
        userBehaviorService.addViews(userBehaviorDTO);
    }

    /**
     * 处理查询浏览历史的请求
     *
     * @param shopPageQueryDTO 分页查询参数的DTO
     * @return 浏览历史的分页结果
     */
    @GetMapping("/history")
    public PageResult history(ShopPageQueryDTO shopPageQueryDTO) {
        return userBehaviorService.history(shopPageQueryDTO);
    }
}
